import Vue from 'vue'
import reshandler from 'services/response-handler'
/*
 * 用户信息 通过账号密码获取
 * 签到
 */
function makeUserData(userInfo) {
    console.log(userInfo)
    let sign = '';
    let headimg = '';
    if (userInfo.signInState === "0") {
        sign = "未签到";
    } else {
        sign = "已签到";
    }
    return {
        userName: userInfo.userNickname,
        bean: 'V豆:' + userInfo.bean,
        gender: userInfo.userGender,
        headerUrl: userInfo.headerUrl,
        sign: sign,
        rank: userInfo.rank
    }
}
function makeSignData(data){
    console.log(data);
    return{
        bean:'V豆:'+data.bean
    }
}
function makeWeatherData(data) {
    console.log(data);
    console.log(data[0]);
    let weatherData = JSON.parse(data.weatherJson)
    console.log(weatherData);
    let Max = weatherData.result.HeWeather5[0].daily_forecast[0].tmp.max;
    let Min = weatherData.result.HeWeather5[0].daily_forecast[0].tmp.min;
    let Status = weatherData.result.HeWeather5[0].daily_forecast[0].cond.txt_d;
    let weather = Min + '° ~ ' + Max + '° ' + Status;
    console.log(weather+'-----------------')
    return{
        weather: weather
    }
}

export default function (params, success, fail) {
    console.log(params)
    let make;
    switch (params.methodName) {
        case 'QueryUserInfo':
            make = makeUserData
            break;
        case 'SignForPlatform':
            make = makeSignData
            break;
        case 'QueryWeather':
            make = makeWeatherData
            break;
    }
    this.$.get(params).then(reshandler.success(success, fail, make), reshandler.error(fail))
}
